DXL communication with other code

I am looking for a way to get a trigger in Doors to communicate with or run some C# code that I have written (to do some database work, messaging, and other things). It is pretty easy to go the other way (have C# initiate, run, and communicate with some DXL), but I can't seem to find a good way to do it with a trigger/DXL initiating the communication.

Ideal Methods that I can't find a way to do:

1) When trigger occurs, run an executable file directly instead of a dxl file

2) When trigger occurs, run a dxl file which then: Runs an executable file directly

3) When trigger occurs, run a dxl file which then: Sets up a socket or some type of network communication with a C# service and tells service to run

Non-Ideal methods that I can get to work but would prefer one of the above:

1) Have the trigger DXL modify a text file and have a C# service also monitoring that text file (basically text file communication)

2) Have a C# service hooking/monitoring Doors output looking for 'special output messages' that only come from the trigger DXL output.

 

Anybody have any experience/tips getting one of the above ideal methods working? Or perhaps a different approach to solving the problem?

 

Any help or tips would be appreciated! Thanks.

 

 


Phippsmx - Mon Oct 21 16:06:42 EDT 2013

Re: DXL communication with other code
Adamarla - Tue Oct 22 02:51:41 EDT 2013

To run an exe, you are looking for:

void system(string commandString)

or to get returned data or/and wait for it to finish:

int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

-Adam

 

Re: DXL communication with other code
llandale - Tue Oct 22 12:08:47 EDT 2013

Adamarla - Tue Oct 22 02:51:41 EDT 2013

To run an exe, you are looking for:

void system(string commandString)

or to get returned data or/and wait for it to finish:

int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

-Adam

 

Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

  • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
  • string Command = "c:/Wherever/Whatever.exe /Parameters"
  • string SysCommand = c_ComSpec " /c " Command
  • system(SysCommand)
  • sleep_(2000)    // give it 2 seconds to finish
  • proceed...

Oddly, I cannot get the wait version to work on my system.

-Louie

IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

Re: DXL communication with other code
pommCannelle - Fri Oct 25 08:58:24 EDT 2013

llandale - Tue Oct 22 12:08:47 EDT 2013

Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

  • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
  • string Command = "c:/Wherever/Whatever.exe /Parameters"
  • string SysCommand = c_ComSpec " /c " Command
  • system(SysCommand)
  • sleep_(2000)    // give it 2 seconds to finish
  • proceed...

Oddly, I cannot get the wait version to work on my system.

-Louie

IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

Hi Louie, 

Here after an old function made to wait the end of the action launched by the system function.

The wait_time_in_sec  value is here to put a limit to the waiting phase ...

    string command_system (string cmd, int wait_time_in_sec) {
       int wait_time_in_ms = 1000*wait_time_in_sec
       string errmsg = null
       
       // create the lock file : while it exists the command is still running
       string lockfile = tempFileName          // ( os give us a legal temp file )
       string errmsgfile = tempFileName
       Stream out = write lockfile            // create the temp file ...
       close out
       
       // make the batchfile command
       string batchfile = tempFileName ".bat"
       out = write batchfile
       out << cmd " 2> \"" errmsgfile "\"\n"    // ( error treatment )
       out << "if %errorlevel% EQU 0 del \"" errmsgfile "\"\n"
       out << "del \"" lockfile "\"\n"
       close out
       
       // run the batchfile command
       system batchfile                  // send the batchfile command to system
             
       // Wait for the batchfile command to end
       int delay_in_ms = 0
       while (fileExists_ lockfile) {         // wait the lock file deletion
           if (delay_in_ms > wait_time_in_ms){   // ( timer )
              // abort if delay > tempo s
              errmsg = "Timeout ! (" wait_time_in_sec " sec)"
              break
           }
           delay_in_ms += 100     
           sleep_(100)                      // sleep_ funcion used for 100 ms
       }
       deleteFile batchfile               // ( clean the batch file )
       
       // return error message if any
       if (null errmsg && fileExists_ errmsgfile){
          errmsg = readFile errmsgfile
       }
       deleteFile errmsgfile
       return errmsg
    }

Have fun !

Re: DXL communication with other code
Phippsmx - Fri Oct 25 16:56:39 EDT 2013

Adamarla - Tue Oct 22 02:51:41 EDT 2013

To run an exe, you are looking for:

void system(string commandString)

or to get returned data or/and wait for it to finish:

int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

-Adam

 

Thanks for the help. Exactly what I was looking for.